package com.zenithmind.news.pojo.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 新闻审核实体类 - 遵循单一职责原则
 * 专门负责新闻的审核相关信息
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("news_audit")
@Schema(description = "新闻审核实体")
public class NewsAudit extends BaseEntity {

    /**
     * 新闻ID
     */
    @Schema(description = "新闻ID")
    private String newsId;

    /**
     * 审核状态（0-待审核，1-审核通过，2-审核失败）
     */
    @Schema(description = "审核状态（0-待审核，1-审核通过，2-审核失败）")
    private Integer auditStatus = 0;

    /**
     * 审核者ID
     */
    @Schema(description = "审核者ID")
    private String reviewerId;

    /**
     * 审核者名称
     */
    @Schema(description = "审核者名称")
    private String reviewerName;

    /**
     * 审核意见
     */
    @Schema(description = "审核意见")
    private String reviewComment;

    /**
     * 审核时间
     */
    @Schema(description = "审核时间")
    private LocalDateTime reviewTime;

    /**
     * 审核通过
     */
    public void approve(String reviewerId, String reviewerName, String comment) {
        this.auditStatus = 1;
        this.reviewerId = reviewerId;
        this.reviewerName = reviewerName;
        this.reviewComment = comment;
        this.reviewTime = LocalDateTime.now();
    }

    /**
     * 审核拒绝
     */
    public void reject(String reviewerId, String reviewerName, String comment) {
        this.auditStatus = 2;
        this.reviewerId = reviewerId;
        this.reviewerName = reviewerName;
        this.reviewComment = comment;
        this.reviewTime = LocalDateTime.now();
    }

    /**
     * 是否已审核
     */
    public boolean isReviewed() {
        return this.auditStatus != null && this.auditStatus != 0;
    }

    /**
     * 是否审核通过
     */
    public boolean isApproved() {
        return this.auditStatus != null && this.auditStatus == 1;
    }

    /**
     * 是否审核失败
     */
    public boolean isRejected() {
        return this.auditStatus != null && this.auditStatus == 2;
    }
}
